package com.cloud.spring.demo.controller;

import com.cloud.spring.demo.entity.Address;
import com.cloud.spring.demo.entity.User;
import com.cloud.spring.demo.feign.EurekaClient2Feign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {
    @Autowired
    EurekaClient2Feign eurekaClient2Feign;

    @GetMapping("getUser")
    public User getUser(int id) {
        return eurekaClient2Feign.getUser(id);
    }

    @GetMapping("getUserList")
    public List<User> getUserList() {

        return eurekaClient2Feign.getUserList(createUser());
    }

    @GetMapping("saveUserList")
    public List<User> saveUserList() {
        List<User> userList = new ArrayList<>();
        userList.add(createUser());
        userList.add(createUser());
        return eurekaClient2Feign.saveUserList(userList);
    }

    public User createUser() {
        User user = new User();
        user.setId(1);
        user.setName("tom");
        user.setCreateTime(LocalDateTime.now());
        Address address = new Address();
        address.setId(1);
        address.setMessage("YanTai");
        user.setAddress(address);
        return user;
    }
}
